package com.study.mall.design.observer;

import java.util.ArrayList;
import java.util.List;

public class Subject {
    //所有观察者的集合
    private List<Observer> observers  = new ArrayList<Observer>();

    public void attach(Observer observer) {
        observers.add(observer);
    }

    public void detach(Observer observer) {
        observers.remove(observer);
    }

    //通知所有的观察者
    public void notifyObservers() {
        for (Observer observer : observers) {
            observer.update(this);
        }
    }

}
